package org.jeecg.glr.job;


import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.jeecg.glr.service.*;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 路灯网关统计数据统一处理
 * 定时任务
 */
@Slf4j
public class UpdateStatusJob implements Job {

    @Value(value = "${spring.quartz.job.update_status_is_runing}")
    private String update_status_is_runing;

    @Autowired
    private IGlrVideoService glrVideoService;

    @Autowired
    private IGlrRadioService glrRadioService;

    /**
     * 摄像头音柱在线状态更新 定时更新状态 半小时一次
     * 0 0/3 * * * ? *三分钟一次
     * 0 0/30 * * * ? *半小时一次
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        long start = System.currentTimeMillis();
        String stJobName="摄像头音柱在线状态更新";
        log.info(String.format("1处理"+stJobName+"定时任务开始!===时间:" + DateUtils.getTimestamp()));
        try{

            if (!"Y".equals(update_status_is_runing.toUpperCase())){
                log.info("2===================处理"+stJobName+"定时任务取消===================");
                return;
            }

            try{
                glrVideoService.doUpdateStatus();
            }
            catch (Exception ex){

            }

            try{
                glrRadioService.doUpdateStatus();
            }
            catch (Exception ex){

            }

            log.info("3===================处理"+stJobName+"定时任务结束===================");
        }catch (Exception e){
            e.printStackTrace();
            log.info(e.getMessage());
            log.info("4===================ERROR处理"+stJobName+"定时务错误===================");
        }
        log.info(String.format("5处理"+stJobName+"定时任务结束!===时间:" + DateUtils.getTimestamp()));
        long end = System.currentTimeMillis();
        long times = end - start;
        log.info("6处理"+stJobName+"总耗时" + times + "毫秒");
    }

}
